#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
#define ll long long
#define pfn printf("\n")
#define pii pair<int,int>
#define pcc pair<char,char>
#define INF 1e9+7
#define endl "\n"//有交互把这个给注释
const double EPS=0.000000001;
const ll mod=998244353;
//const ll p1=131,mod1=998244353,p2=2333,mod2=1e9+7;//哈希数
struct StudentInfo {
    std::string class_id;
    std::string name;
    std::string student_id;
    int attempt_count;
};

// 定义房子结构
struct House {
    int color;       // 房子颜色
    int nationality; // 国籍
    int drink;       // 饮料
    int cigarette;   // 香烟品牌
    int pet;         // 宠物
};

// 模拟退火算法
class SimulatedAnnealingSolver {
private:
    static const int NUM_HOUSES = 5;   
    House houses[NUM_HOUSES];        
    double temperature;               
    double coolingRate;              

   
    void initializeSolution() {
        // 随机初始化房子的属性
      
        for (int i = 0; i < NUM_HOUSES; i++) {
            houses[i].color = rand() % NUM_HOUSES;
            houses[i].nationality = rand() % NUM_HOUSES;
            houses[i].drink = rand() % NUM_HOUSES;
            houses[i].cigarette = rand() % NUM_HOUSES;
            houses[i].pet = rand() % NUM_HOUSES;
        }
    }

    // 计算当前解的冲突数（目标函数）
    int calculateConflict() {
        int conflictCount = 0;
        // 根据题目条件计算冲突数
        if (houses[0].nationality != NORWEGIAN) conflictCount++; //条件9
        if (houses[2].drink != MILK) conflictCount++;            // 条件8
        // 其他条件...

        return conflictCount;
    }

    // 生成邻域解，通过交换两个房子的属性
    void generateNeighborSolution() {
        int house1 = rand() % NUM_HOUSES;
        int house2 = rand() % NUM_HOUSES;
        // 随机交换house1和house2的某个属性
        std::swap(houses[house1].color, houses[house2].color);
    }

    // 模拟退火
    bool acceptSolution(int deltaConflict) {
        if (deltaConflict < 0) return true; // 如果新解更优，直接接受
        double acceptanceProbability = exp(-deltaConflict / temperature);
        return (rand() / (double)RAND_MAX) < acceptanceProbability;
    }

public:
    SimulatedAnnealingSolver(double initialTemp, double coolingRate) : temperature(initialTemp), coolingRate(coolingRate) {
        initializeSolution();
    }

    // 开始模拟退火
    void solve() {
        while (temperature > 1e-3) {
            int currentConflict = calculateConflict();
            generateNeighborSolution();
            int newConflict = calculateConflict();
            int deltaConflict = newConflict - currentConflict;

            if (acceptSolution(deltaConflict)) {
                // 新解
                if (newConflict == 0) {
                    // 找到满足所有条件的解
                    break;
                }
            } else {
                // 拒绝新解，恢复原解
                generateNeighborSolution(); // 回到原解
            }
            // 降温
            temperature *= coolingRate;
        }
    }

    // 输出解
    void printSolution() {
        for (int i = 0; i < NUM_HOUSES; i++) {
            std::cout << "House " << i + 1 << ": ";
            std::cout << "Color=" << houses[i].color << ", ";
            std::cout << "Nationality=" << houses[i].nationality << ", ";
            std::cout << "Drink=" << houses[i].drink << ", ";
            std::cout << "Cigarette=" << houses[i].cigarette << ", ";
            std::cout << "Pet=" << houses[i].pet << std::endl;
        }
    }
};

int main() {
    
    SimulatedAnnealingSolver solver(100.0, 0.95);  // 初始温度100，降温因子0.95
    solver.solve();
    solver.printSolution();
    return 0;
}